<template>
    <div></div>
</template>

<script>
export default {
    name: 'LoginComponents',
    data() {
        return {
            loginName: '',
            password: '',
            user: null
        }
    },
    methods: {
        toIndex() {
            if (!(this.$route.path === '/')) {
                this.$router.push({ name: 'index' })
            }
        },
        toLogin() {
            this.$axios({
                url: '/login',
                params: { loginName: this.loginName, password: this.password }
            }).then(rs => {
                if (rs.data.code == 5200 || rs.data.code == '5200') {
                    console.log(rs.data)
                    this.user = rs.data.user
                    console.log(this.user)
                    // 保存用户信息到localStorage（长期存储）
                    localStorage.setItem('user', JSON.stringify(rs.data.user));
                    alert("登录成功！")
                    this.setShowPage(0)
                    this.$router.push('/')
                }
            })
        },
        toRegister() {
            this.setShowPage(1)
            this.$router.push('/regist')
        }
    }
}
</script>

<style></style>